var _set = require("../../../API/set.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keywords:'',
    loadend: !1,
    page: 1,
    list:[],
    listShow:0,
    userShopList:[],
    reasonIndex:-1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserList();
  },
  search:function(e){
    this.setData({
      keywords:e.detail.value
    })
  },
  toSearch:function(){
    this.getList();
  },
  toBindShop:function(){
    var self = this;
    if(this.data.reasonIndex != -1){
      (0, _set.toBindShop)({
          shop_id:this.data.list[this.data.reasonIndex].id
        }).then(function(t) {
          self.getUserList();
          self.setData({
            listShow:0
          })
          return app.Tips({
            title: '绑定成功'
          });
        }).catch(function(t) {
          return app.Tips({
              title: t
          });
      });
    }
  },
  toDeliver:function(e){
    var idx = e.currentTarget.dataset.idx
    app.globalData.addrInfo ={
      address:this.data.userShopList[idx].address,
      name:this.data.userShopList[idx].name,
      phone:this.data.userShopList[idx].phone,
      shop_id:this.data.userShopList[idx].pivot.shop_id,
      realname:this.data.userShopList[idx].realname
    }
    wx.navigateTo({
      url: '/home/pages/photograph/index',
    })
  },
  toUnbindShop:function(e){
    var self = this;
    (0, _set.toUnbindShop)({
        shop_id:e.currentTarget.dataset.idx
      }).then(function(t) {
        app.globalData.addrInfo = {};
        self.getUserList();
        return app.Tips({
          title: '解绑成功'
        });
      }).catch(function(t) {
        return app.Tips({
            title: t
        });
    });
  },
  getUserList:function(){
    var self = this;
    (0, _set.getUserShopList)().then(function(t) {
      self.setData({
        userShopList:t.data
        })
    }).catch(function(t) {
      return app.Tips({
          title: t
      });
  });
  },
  getList:function(){
    var self = this;
    (0, _set.getBindShopList)({
        keywords:self.data.keywords
    }).then(function(t) {
        self.setData({
          list: t.data,
          listShow:1
        });
    }).catch(function(t) {
      return app.Tips({
          title: t
      });
  });
  },
  onChangeCancelReason: function(t) {
    this.setData({
        reasonIndex: t.detail
    });
},
  hideShow:function(){
    this.setData({
      listShow:0
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getUserList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})